from tortoise.models import Model
from tortoise import fields


class Role(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255, description="角色名称")
    code = fields.CharField(max_length=255, description="角色标识")
    enable = fields.IntField(description="是否启用", default=1)
    remark = fields.CharField(max_length=255, description="备注", null=True)
    details = fields.CharField(max_length=255, description="详情", null=True)
    sort = fields.IntField(description="排序", default=0)
    create_time = fields.DatetimeField(auto_now_add=True, description="创建时间")
    update_time = fields.DatetimeField(auto_now=True, description="更新时间")
    powers: fields.ManyToManyRelation["Power"] = fields.ManyToManyField(
        "models.Power",
        through="admin_role_power",
    )

    # 关系将在使用时通过 Tortoise 的关系定义方式建立

    class Meta:
        table = "admin_role"
